<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>物业管理系统登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="./js/layui/css/layui.css">
    <link rel="stylesheet" href="./admin/css/login.css">
    <link rel="stylesheet" href="./js/layui/css/layui.css">
    <link rel="stylesheet" href="./admin/css/login.css">
    <style>
        .layui-anim-upbit{
            color:black !important;
        }
    </style>
</head>
<body>
<div class="user-login user-display-show" id="user-login">
    <div class="loginForm layui-bg-black" style="position: relative;left: 50%;transform: translateX(-50%);">
        <div class="user-login-main">
            <div class="user-login-box user-login-header">
                <h3>物业管理系统</h3>
            </div>
            <div class="user-login-box user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input  type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码"
                            class="layui-input">
                </div>
                <select name="city" style="color:black !important;" lay-filter="login">
                    <option value="1">管理员登录</option>
                    <option value="2">物业登录</option>
<!--                    <option value="3">医生登录</option>-->
                    <option value="4">商户登录</option>
                    <option value="5">充值点登录</option>
<!--                    <option value="6">工商登录</option>-->
<!--                    <option value="7">集团办公室登录</option>-->
                    <option value="8">证件管理登录</option>
                </select>
                <div class="layui-form-item">
                    <button id="loginBtn" class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-trans user-login-footer">
        <p>© 2021 <a href="#" target="_blank">物业管理系统</a></p>
    </div>
</div>
<script src="./js/layui/layui.all.js"></script>
<script src="./js/token.js"></script>
<script src="./js/config.js"></script>
<script>

    var layer = layui.layer;
    var form = layui.form;
    var login_type = 1 ;
    var $ = layui.$;
    $("#loginBtn").click(function () {
        var username = $("#LAY-user-login-username").val();
        var password = $("#LAY-user-login-password").val();
        var code2 = $("#loginCard").val();
        if(username==null||username==''){
            layer.msg("用户名不能为空");
            return;
        }
        if(password==null||password==''){
            layer.msg("密码不能为空");
            return;
        }
        if(login_type == 1) {   //管理员登录
            $.ajax({
                url: HOST + 'admin/adminLogin',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        localStorage.setItem("username",username);
                        localStorage.setItem("admin_id",data.data.id);
                        layui.data('local_store',{key:'token',value:data.data.token});
                        layer.msg("登录成功",{
                                icon:1,
                                time:2000,
                                end:function () {
                                    window.location.href="main.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if (login_type == 2) {
            $.ajax({
                url: HOST + 'login/wuye',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        localStorage.setItem("username",username);
                        localStorage.setItem("admin_id",data.data.id);
                        layui.data('local_store',{key:'token',value:data.data.token});
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="wuye.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if(login_type == 3) {
            $.ajax({
                url: HOST + 'login/doctor',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/doctor.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if(login_type == 4) {
            $.ajax({
                url: '/login/business',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/business.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if(login_type == 5) { //充值点登录
            $.ajax({
                url: '/login/recharge',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/recharge.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if (login_type == 6) { //工商职业登录
            $.ajax({
                url: '/login/businessOccupation',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/business_occupation.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if (login_type == 7) { //集团办公室登录
            $.ajax({
                url: '/login/groupOffice',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/group_office.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if (login_type == 8) { //证件管理登录
            $.ajax({
                url: '/login/certificate',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/certificate_manage.html";
                                }
                            }
                        );
                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                },
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if (login_type == 2) {
            $.ajax({
                url: HOST+'login/wuye',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="wuye.html";
                                }
                            }
                        );

                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                }
                ,
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if(login_type == 3) {
            $.ajax({
                url: HOST+'login/qiye',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/qiye.html";
                                }
                            }
                        );

                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                }
                ,
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else if(login_type == 4) { //充值点登录
            $.ajax({
                url: HOST+'login/recharge',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/recharge.html";
                                }
                            }
                        );

                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                }
                ,
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }
        else if (login_type == 5) { //证件管理登录
            $.ajax({
                url: HOST+'login/certificate',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/certificate_manage.html";
                                }
                            }
                        );

                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                }
                ,
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }
    });

    form.on("select(login)" , function(res) {
        login_type = res.value
    })

    $(window).keypress(function (event) {
        if(event.which === 13){
            $('#loginBtn').click();
        }
    })
</script>
</body>
</html>